package com.neusoft.nep.grid.entity;
import com.neusoft.nep.common.FileUtils;
import javafx.collections.FXCollections;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

import static com.neusoft.nep.common.FileUtils.readMapObject;

public class Fankui implements Serializable {
    private static final long serialVersionUID = -3931078088574099231L;
    private String code;
    private String returnperson;
    private String time;
    private String level;
    private String sheng;
    private String shi;
    private String aqi;
    public Fankui(String code, String returnperson,  String level, String sheng, String shi, String time, String aqi) {
        this.code = code;
        this.returnperson = returnperson;
        this.time = time;
        this.level = level;
        this.sheng = sheng;
        this.shi = shi;
        this.aqi = aqi;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getReturnperson() {
        return returnperson;
    }

    public void setReturnperson(String returnperson) {
        this.returnperson = returnperson;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getSheng() {
        return sheng;
    }

    public void setSheng(String sheng) {
        this.sheng = sheng;
    }

    public String getShi() {
        return shi;
    }

    public void setShi(String shi) {
        this.shi = shi;
    }


    public String getAqi() {
        return aqi;
    }

    public void setAqi(String aqi) {
        this.aqi = aqi;
    }

    public static Fankui findfankuiByCode(String fileName, String Code) {
        Map<String, Fankui> FankuiMap = readMapObject(fileName);
        return FankuiMap.get(Code); // 直接通过键获取用户
    }

    // 将Fankui对象写入新文件
    public static void writeNewFankuiMap(Map<String, Fankui> map) {
        String fileName = "Fankui2.txt";

        try {
            // 读取现有文件内容（如果存在）
            Map<String, Fankui> existingData = FileUtils.readMapObject(fileName);

            // 将新数据合并到现有数据中
            if (existingData == null) {
                existingData = new HashMap<>();
            }
            existingData.putAll(map);

            // 将合并后的数据写回文件
            FileUtils.writeMapObject(fileName, existingData);
            System.out.println("已更新处理后的反馈信息到: " + fileName);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("保存处理后的反馈信息时出错: " + e.getMessage());
        }
    }
    public static void saveToNewFile(String code, Fankui fankui) {
        Map<String, Fankui> newMap = new HashMap<>();
        newMap.put(code, fankui);
        // 保存到新文件
        writeNewFankuiMap(newMap);
    }
    
}



